package com.pay.ioopos.fragment;

import android.graphics.Typeface;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Switch;
import android.widget.TextView;

import androidx.fragment.app.Fragment;

import com.pay.ioopos.IconFontFactory;
import com.pay.ioopos.KeyCodeFactory;
import com.pay.ioopos.KeyInfo;
import com.pay.ioopos.R;


public class SwitchFragment extends Fragment implements View.OnKeyListener {

    private Switch switchBt;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_switch, container, false);

        switchBt = view.findViewById(R.id.switch_bt);
        switchBt.setFocusable(true);
        switchBt.requestFocus();
        switchBt.setOnKeyListener(this);

        return view;

    }

    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        KeyInfo keyInfo = KeyCodeFactory.getKeyInfo(keyCode);
        if (null == keyInfo) {
            return false;
        }
        if (event.getAction() != KeyEvent.ACTION_DOWN) {
            return false;
        }
        switch (keyInfo) {
            case KEY_UP:
                switchBt.setChecked(false);
                return true;
            case KEY_DOWN:
                switchBt.setChecked(true);
                return true;
            case KEY_NUM_1:
                switchBt.setChecked(false);
                return true;
            case KEY_NUM_2:
                switchBt.setChecked(true);
                return true;
        }

        return false;
    }
}
